﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.factory;
using Imaginecup.gameState.malaria.component.factory;
using imaginecup.objectManager;
using Imaginecup.gameState.malaria.componentInit;
using imaginecup.information;
using Imaginecup.util;
using Imaginecup.gameState.malaria.component.entity.fieldItem;
using imaginecup.util;
using Microsoft.Xna.Framework;
using Imaginecup.gameState.malaria.manager;
using Imaginecup.util.collision;
using Imaginecup.util.script.malaria;

namespace Imaginecup.gameState.malaria.component.entity.item
{
    public class CmpFrogItem : BaseItemEntityComponent
    {
        private int m_RequireMoney;
        private double m_FrogDelayTime;

        public CmpFrogItem(GObjectID a_GID, ObjectManager objMan)
            : base(a_GID, objMan, ComponentTypeID.CID_ITEM_ENTITY)
        {
            

            m_RequireMoney = 3;
            m_FrogDelayTime = 20;

//#if WINDOWS
//            m_RequireMoney = ScriptReader.GetScriptReader().GetDataToInt("개구리돈");
//            m_FrogDelayTime = ScriptReader.GetScriptReader().GetDataToFloat("개구리유지시간");
//#endif
        }

        public override EMessageResult HandleMessage(GMessage a_Msg)
        {
            if (a_Msg.m_Type.MessageTypeID == MessageTypeID.MT_CHECK_INPUT.MessageTypeID)
            {

            }

            
            return base.HandleMessage(a_Msg);
        }

        public override bool IsUseAble()
        {
            if (!IsSelectAble()) return false; 

            IMouseInputHandler input = MouseInputHandler.GetInputHandler();

            Vector2 screen = MalariaState.GetMalariaState().GetMainScreenSize();

            if (input.IsOneClickUp() && Collision.ContainPoint(Vector2.Zero, screen, input.Position))
            {
                return true;
            }
            return false;
        }

        public override void DisableItem()
        {

            base.DisableItem();
        }

        public override void UseItem(GameTime gameTime)
        {
            IMouseInputHandler input = MouseInputHandler.GetInputHandler();

            ObjectFactory.GetObjectFactory().SetObjectMan(m_ObjectMan);
            CmpFieldFrog flog = (CmpFieldFrog)ObjectFactory.GetObjectFactory().GetObject(MALARIA_COMPONENT_ID.FIELD_FROG);

            EntityInfo info = new EntityInfo();
#if !XBOX
            info.mPosition = new Vector2(input.MouseState.X, 320);//input.MouseState.Y);
#endif
#if XBOX
            info.mPosition = input.Position;
#endif
            info.mSize = new Vector2(50, 50);

            flog.SetDelayTime(m_FrogDelayTime);
            flog.SetEntityInfo(info);

            GameResourceMan.GetResourceMan().AddMoney(-m_RequireMoney);
        }

        public override bool IsStateEnd()
        {
            return false;
        }

        public override bool IsSelectAble()
        {
            if (GameResourceMan.GetResourceMan().GetMoney() > m_RequireMoney)
            {
                return true;
            }

            return false;
        }
    }
}
